{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
~}}

<PageHeader as |p|>
  <p.levelLeft>
    <h1 class="title is-3">
      Unwrap Data
    </h1>
  </p.levelLeft>
</PageHeader>

{{#if @unwrap_data}}
  <Hds::Tabs as |T|>
    <T.Tab data-test-button-data>Data</T.Tab>
    <T.Tab data-test-button-details>Wrap Details</T.Tab>
    <T.Panel>
      <JsonEditor
        class="has-top-padding-m"
        @title="Unwrapped Data"
        @value={{stringify @unwrap_data}}
        @readOnly={{true}}
        @container=".toolbar-actions"
      />
    </T.Panel>
    <T.Panel>
      <div class="has-top-padding-m">
        {{#each-in @details as |key detail|}}
          <InfoTableRow @label={{key}} @value={{key}}>
            {{#if (or (eq detail "No") (eq detail "None"))}}
              <Icon @name="x-circle" class="has-text-grey" />
              {{detail}}
            {{else}}
              {{#if (eq detail "Yes")}}
                <Icon @name="check-circle" class="has-text-success" />
              {{/if}}
              {{detail}}
            {{/if}}
          </InfoTableRow>
        {{/each-in}}
      </div>
    </T.Panel>
  </Hds::Tabs>
  <Hds::ButtonSet class="has-top-padding-m">
    <Hds::Copy::Button @text="Copy unwrapped data" @textToCopy={{stringify @unwrap_data}} class="primary" />
    <Hds::Button {{on "click" this.onClear}} @color="secondary" @text="Back" />
  </Hds::ButtonSet>
{{else}}
  <div class="box is-sideless is-fullwidth is-marginless">
    <NamespaceReminder @mode="perform" @noun={{@selectedAction}} />
    <MessageError @errors={{@errors}} />
    <div class="field">
      <label for="token" class="is-label">Wrapped token</label>
      <div class="has-text-grey is-size-8 has-bottom-margin-xs">
        Enter your wrapped token here to unwrap it and return its original value.
      </div>
      <div class="control">
        <Input
          @value={{@token}}
          class="input"
          id="token"
          name="token"
          autocomplete="off"
          spellcheck="false"
          data-test-tools-input="wrapping-token"
        />
      </div>
    </div>
  </div>
  <div class="field is-grouped box is-fullwidth is-bottomless">
    <div class="control">
      <Hds::Button @text="Unwrap data" type="submit" data-test-tools-submit="true" />
    </div>
  </div>
{{/if}}